<?php
$total = count($this->nmsg);
$file  = Engine_Api::_()->getApi('storage', 'storage');
?>
<?php if ($total):?>
<?php $unread = array();?>
<?php foreach ($this->nmsg as $item):?>
	<?php $unread[] = $item->notification_id?>
<?php endforeach;?>
<script type="text/javascript">
$('notification_count').getParent().setStyle('display', '');
$('notification_count').innerHTML = '<?php echo $total;?>';
var notification_msg = [<?php echo implode(', ', $unread)?>];
</script>
<?php else:?>
<script type="text/javascript">
var notification_msg = new Array();
</script>
<?php endif;?>
<script type="text/javascript">
function markAllRead()
{
      en4.core.request.send(new Request.JSON({
        url : en4.core.baseUrl + 'advmenusystem/index/markallread',
        data : {
          format     : 'json'
        }
       }));  
}
function makeRead(actionid)
{
      en4.core.request.send(new Request.JSON({
        url : en4.core.baseUrl + 'advmenusystem/index/markread',
        data : {
          format     : 'json',
          'actionid' :  actionid
        },
        'onComplete' : function(response)
        {
              var content = $('content_'+actionid).innerHTML;
              var arrHref = content.split("href");
              if(arrHref[2])
              {
                var strlink = arrHref[2];
                var arrstr = strlink.split('"');
                window.location = arrstr[1];
              }
              else if(arrHref[1])
              {
                  strlink = arrHref[1];
                  arrstr = strlink.split('"');
                  window.location = arrstr[1]; 
              }    
        }
      })); 
}
</script>
<ul id="notifications_main">	
<?php if (count($this->msg)): ?>
<?php foreach ($this->msg as $item):?>
	<?php $subject = $item->getSubject()?>
	<li onclick="makeRead(<?php echo $item->getIdentity();?>)"  class= "item_content" value="<?php echo $item->getIdentity();?>" >
	<table border="0" width="100%" cellspacing="0" cellpadding="0">
		<tr>
			<td>
			<?php echo $this->itemPhoto($subject, 'thumb.icon');?>    
			</td>
			<td style="width: 80%;">
				<div class="data" onclick="makeRead(<?php echo $item->getIdentity();?>)" >
					<div class="notification_content" id="content_<?php echo $item->getIdentity();?>" class="content" <?php if( !$item->read ): ?> style="font-weight: bold;"<?php endif; ?>><?php echo $item->getContent();?></div>
					<div style=" background-repeat: no-repeat;display: block; padding-left: 18px;" class="notification_item_general notification_type_<?php echo $item->type ?>"><?php echo $this->timestamp($item->date)?></div>
				</div>
				<div style="clear:both"></div>				
			</td>
		</tr>
	</table>
	</li>
<?php endforeach;?>
<?php else:?>
<div class="no_item_content"><span class="none"><?php echo $this->translate('No new notifications.')?></span></div>
<?php endif;?>
<li class = "sfooter">
	<a href="<?php echo $this->baseUrl()?>/adv-menu-system/notifications"  style="text-decoration: none; padding-right: 20px; font-weight: bold; padding-left: 20px;">
		<span><?php echo $this->translate('See All Notifications')?></span>
	</a>
    <a href="javascript:;" onclick="markAllRead()" style="text-decoration: none; font-weight: bold;">
        <span><?php echo $this->translate('Mark All Read')?></span>
    </a>
</li>
</ul>
